package org.emet.flex.services
{
	import mx.rpc.AbstractOperation;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.mxml.Operation;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	public class RemoteOper 
	{
		private var ro:RemoteObject;
		private var resultCallback:Function;
		private var faultCallback:Function;
		
		public function RemoteOper(ro:RemoteObject):void
		{
			this.ro = ro;
		}
		
		public function execute(method:String,... args:Array):void
		{
			var m:AbstractOperation = ro.getOperation(method);
			m.send(args);
		}
		
		public function setResultCallback(resultCallback:Function):void {
			ro.addEventListener(ResultEvent.RESULT, resultCallback,false,0,true);
		}
		
		public function setFaultCallback(faultCallback:Function):void {
			ro.addEventListener(FaultEvent.FAULT,faultCallback,false,0,true);
		}
		
		public function cleanCallbacks():void {
			ro.removeEventListener(ResultEvent.RESULT, resultCallback);
			ro.removeEventListener(FaultEvent.FAULT, faultCallback);
		}
		
	}
}